package xkp.lesson5;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

public class ReadDataUi extends JFrame {
    public ReadDataUi(){
        //设置窗体尺寸
        this.setSize(700,100);
        //禁止改变大小
        this.setResizable(false);
        this.setTitle("登录");
        this.setLocationRelativeTo(null);
        //此处是隐藏并关闭
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        FlowLayout flowLayout = new FlowLayout(FlowLayout.CENTER);
        this.setLayout(flowLayout);
        JLabel jLabelJob = new JLabel("职位");
        jLabelJob.setFont(new Font("黑体", Font.BOLD, 24));
        this.add(jLabelJob);
        JTextField jobText = new JTextField();
        jobText.setPreferredSize(new Dimension(240,40));
        this.add(jobText);

        JLabel jLabelCity = new JLabel("城市");
        jLabelCity.setFont(new Font("黑体", Font.BOLD, 24));
        this.add(jLabelCity);
        JTextField cityText = new JTextField("");
        cityText.setPreferredSize(new Dimension(240,40));
        this.add(cityText);
        JButton beginBtn = new JButton("开始");
        beginBtn.setFont(new Font("黑体", Font.BOLD, 24));
        this.add(beginBtn);
        beginBtn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String city = cityText.getText().trim();
                String kw = jobText.getText().trim();
                try {
                    ReadDataUtils.readData(city,kw,1);
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
        });

        this.setVisible(true);
    }

}
